﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 链表
{
    public class node<T>
        { 
            public node<T> Next { get; set; }
            public T data { get; set; }
            public node(T t)
            {
                Next = null;
                data = t;
            }
        }
        public class list<T>
        {
            private node<T> head;
            private node<T> tail;
            public list()
            {
                tail = head = null;
            }
            public node<T> Head
            {
                get => head;
            }
            public void add(T t)
            {
                node<T> n = new node<T>(t);
                if(tail == null)
                {
                    head = tail = n;
                }
                else
                {
                    tail.Next = n;
                    tail = n;
                }
            }

        public void ForEach(Action<T> action)
        {
            for (node<T> it = head; it != null; it = it.Next)
            {
                action(it.data);
            }
        }
    }
    class Program
    {
        
    static void Main(string[] args)
        {
            list<int> intlist = new list<int>();
            for(int i=1;i<=10;i++)
            {
                intlist.add(i);
            }
            int min = intlist.Head.data;
            int max = intlist.Head.data;
            int sum = 0;
            intlist.ForEach((x) =>
            {
                min = Math.Min(min, x);
                max = Math.Max(max, x);
                sum += x;
            });
            Console.WriteLine("最大值为：{0}，最小值为：{1}，和为：{2}", max, min, sum);

        }
    }
}
